package com.tinysand.advert.controller;

import com.alibaba.fastjson.JSON;
import com.tinysand.advert.exception.AdvertException;
import com.tinysand.advert.service.AdvertService;
import com.tinysand.advert.support.AdvertRequest;
import com.tinysand.advert.support.AdvertResponse;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

/**
 * 广告相关服务控制器
 *
 * Created By TINY
 * Create Time 2020/2/22
 **/
@Slf4j
@RestController
public class AdvertController {

    private final AdvertService advertService;

    public AdvertController(AdvertService advertService) {
        this.advertService = advertService;
    }

    @PostMapping("/advert/create")
    public AdvertResponse createAdvert(
            @RequestBody AdvertRequest request) throws AdvertException {
        log.info("创建广告，请求参数（{}）", JSON.toJSONString(
                request
        ));

        return advertService.createAdvertisement(request);
    }
}
